package com.iotimc.attendancesystem.io;

import android.media.AudioManager;
import android.media.SoundPool;

import com.iotimc.attendancesystem.App;
import com.iotimc.attendancesystem.R;
import com.iotimc.attendancesystem.entity.BasicSettingEntity;
import com.iotimc.comass.bean.ButtonCommon;

/**
 *
 * @author david
 * @date 2017/12/5
 */

public class ButtonCommonPresenter {
    private ButtonCommon buttonCommon;
    private SoundPool soundPool;
    private static class SingletonHolder {
        private static final ButtonCommonPresenter INSTANCE = new ButtonCommonPresenter();
    }

    public static ButtonCommonPresenter getInstance() {
        return ButtonCommonPresenter.SingletonHolder.INSTANCE;
    }

    private ButtonCommonPresenter(){
        soundPool= new SoundPool(10, AudioManager.STREAM_SYSTEM,5);
        soundPool.load(App.getAppContext(), R.raw.door,1);
        buttonCommon = new ButtonCommon(new ButtonCommon.OnListener() {
            /**
             *
             * @param result
             * @param result
             */

            @Override
            public void getInput(short result, short addr) {

                BasicSettingEntity entity = App.getInstance().getBasicSettingEntity();
                if (entity.getButtonType()== BasicSettingEntity.ButtonType.DOOR_BELL){
                    //收到门铃按钮事件，提示声音
                    soundPool.play(1,1, 1, 0, 2, 1);
                }else {
                    IoCommonPresenter.getInstance().open();
                }
            }
        });
    }


}
